package com.dlyk.controller;

import com.dlyk.DlykServerApplication;
import com.dlyk.bean.TActivity;
import com.dlyk.bean.TDicValue;
import com.dlyk.bean.TProduct;
import com.dlyk.result.DicEnum;
import com.dlyk.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 字典管理
 */
@Slf4j
@RestController
public class DicController {

    /**
     * 获取字典管理数据
     * @param typeCode
     * @return
     */
    @GetMapping("/api/dicValue/{typeCode}")
    public R dicData(@PathVariable String typeCode){
        log.info("字典数据：{}",typeCode);

        if (typeCode.equals(DicEnum.ACTIVITY.getCode())){

            // 获取所有的市场活动
            List<TActivity> activityList =(List<TActivity>)DlykServerApplication.cacheMap.get(typeCode);
            return R.OK(activityList);
        }else if (typeCode.equals(DicEnum.PRODUCT.getCode())){

            // 获取所有的意向产品
            List<TProduct> productList=(List<TProduct>)DlykServerApplication.cacheMap.get(typeCode);
            return R.OK(productList);
        }else {

            // 从缓存中获取类型
            List<TDicValue> dicValueList=(List<TDicValue>)DlykServerApplication.cacheMap.get(typeCode);
            return R.OK(dicValueList);
        }
    }
}
